import { VuexModule, Module, Action, getModule, Mutation } from 'vuex-module-decorators'
import { commonAction } from '@/utils/common'
import store from '@/store'
const currentUrl = window.location.href.split('/')[2]
@Module({ dynamic: true, name: 'oem', store, namespaced: false })
class Oem extends VuexModule {
  public customDomain: any = {}
  public oemFlag: boolean = false
  public oemConfig: any = null
  @Mutation
  public SET_OEMCONFIG (val) {
    this.oemConfig = val
  }

  @Mutation
  public SET_OEMFLAG (val) {
    this.oemFlag = val
  }

  @Action
  public OemCommonAction () {
    return commonAction({ url: `/base/public/platform-info?domain=${currentUrl}` }).then(resp => {
      if (resp.success) {
        this.SET_OEMCONFIG(resp.data.oemConfig)
        this.SET_OEMFLAG(!!resp.data.oemConfig?.customDomain)
      }
      return resp
    })
  }
}

export const OemModule = getModule(Oem)
